package cn.fb.preshop.service;

import cn.fb.preshop.mapper.UserMapper;
import cn.fb.preshop.pojo.User;
import cn.fb.preshop.pojo.UserExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{
    @Resource
    UserMapper userMapper;

    //根据用户名查询用户
    @Override
    public User getSelectUser(String username, String password) {
        UserExample example=new UserExample();
        UserExample.Criteria criteria=example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<User> list=userMapper.selectByExample(example);
        if(list.size()!=0){//有数据时
            if(!list.get(0).getPassword().equals(password)){//当输入的密码跟查询到的数据里的密码不相同时
                return null;
            }//否则就返回查询的数据
            return list.get(0);
        }else{//没查到
            return null;
        }
    }
    //添加用户
    @Override
    public int getInsertUser(User user) {
        return userMapper.insertSelective(user);
    }
}
